/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.gr.sample;
import java.sql.*;
/**
 *
 * @author Hieudt
 */
public class DBConnect {
   public static void main(String[] agrs){
       Connection con = null;
       try {
           String username = "root";
           String pw = "";
           String url = "jdbc:mysql://127.0.0.1:3306/irsystem";
           //
           Class.forName("com.mysql.jdbc.Driver").newInstance();
           con = DriverManager.getConnection(url, username, pw);
           System.out.println("Connected");
            int count =0;
            long start = System.currentTimeMillis(); 
           Statement s = con.createStatement ();
           for(int k=0;k<2;k++)
           for(int i=1;i<11;i++){
           
           s.executeQuery("SELECT id, name, age, gender, job, interest_bg FROM profile WHERE id="+i); 
           count++;
           }
           long end = System.currentTimeMillis(); 
           System.out.println("load "+count+" user data in "+(end-start)+"milis");
//           ResultSet rs = s.getResultSet (); 
//            while (rs.next ()){ 
//           int idVal = rs.getInt ("user_id");                          // int idVal = rs.getInt (1); 
//           String nameVal = rs.getString ("name");  // String nameVal = rs.getString (2);     
//           System.out.println ("ID" + idVal + "Ho v ten:"+nameVal); 
//           } 
//           rs.close (); 
//           s.close (); 
 
           con.close();
           System.out.println("Connection closed");
       } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | SQLException e) {
           System.out.println("Can not connect!");
       }
   }
}
